#ifndef MONITOR_H
#define MONITOR_H

#include <QWidget>
#include <QVBoxLayout>
#include <QLabel>
#include <QScreen>
#include <QGuiApplication>
#include <QTimer>
#include <QMouseEvent>
#include <fstream>
#include <sys/sysinfo.h>
#include <gpumonitorfactory.h>
#include <monitor_settings.h>
#include <kysdk/kysdk-system/libkydisplay.h>
#include <pluginmanager.h>
#include <windowmanager/windowmanager.h>
#include <QSystemTrayIcon>



/**
 * @brief 监视器
 */
class Monitor : public QWidget
{
    Q_OBJECT

public:
    Monitor(QWidget *parent = nullptr);
    ~Monitor();

public slots:
    /**
     * @brief 重新启动
     */
    void restart();

protected:
    void resizeEvent(QResizeEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void moveEvent(QMoveEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private slots:
    void updateStatus();

private:
    /**
     * @brief 设置窗口
     */
    MonitorSettings *settingsWindow;

    /**
     * @brief 系统托盘
     */
    QSystemTrayIcon *systemtray;

    /**
     * @brief 系统托盘菜单
     */
    QMenu *systemtraymenu;

    /**
     * @brief 更新可见性
     */
    void updateLabelVisibility();

    /**
     * @brief 给Label添加样式
     */
    void applyFontStylesToLabels();

    /**
     * @brief 设置背景颜色
     */
    void setBackgroundColor();

    /**
     * @brief 显示菜单
     * @param pos
     */
    void showContextMenu(const QPoint &pos);

    QVBoxLayout *layout;

    /**
     * @brief CPU使用率
     */
    QLabel *cpuUsageLabel;

    /**
     * @brief CPU频率布局框
     */
    QVBoxLayout *cpuFreqLayout;

    /**
     * @brief CPU平均频率
     */
    QLabel *cpuAvgFreqLabel;

    /**
     * @brief CPU频率
     */
    std::vector<QLabel*> cpuFrequencyLabels;

    /**
     * @brief memUsageLabel
     */
    QLabel *memUsageLabel;

    /**
     * @brief gpuCoreUsageLabel
     */
    QLabel *gpuCoreUsageLabel;

    /**
     * @brief gpuMemUsageLabel
     */
    QLabel *gpuMemUsageLabel;

    /**
     * @brief gpuCoreTempLabel
     */
    QLabel *gpuCoreTempLabel;

    /**
     * @brief GPU厂商
     */
    std::unique_ptr<GpuMonitorFactory::GPUVendor> gv;

    /**
     * @brief GPU监视器
     */
    std::shared_ptr<GpuMonitorInterface> gpuMonitor;



    /**
     * @brief 调整屏幕位置
     */
    void adjustPosition();

    void getSysInfo();

    bool mMoveing;
    QPoint mMovePosition;

    /**
     * @brief 插件管理器
     */
    std::unique_ptr<PluginManager> pluginManager;


    /**
     * @brief 当前WindowId
     */
    kdk::WindowId currentWindowId;
};

#endif // MONITOR_H
